package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.Enum.PjCollectionPaymentStatus;
import com.koron.css2.newProjectCenter.bean.PjCollection;
import com.koron.css2.newProjectCenter.bean.query.PjCollectionQuery;
import com.koron.css2.newProjectCenter.mapper.PjCollectionMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.Map;

/**
 * 工程报装-工程收款-详情查看
 *
 * @author 朱超
 * @since 2022-01-19 10:44:39
 */
public class PjCollectionSingle implements ServerInterface {

    /**
     * 缴费方式  用于数据字典取值
     */
    private static final String PAYMENT_METHOD = "BPP";

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjCollectionMapper pjCollectionMapper = factory.getMapper(PjCollectionMapper.class);
            // 1. 获取请求实例
            PjCollectionQuery pjCollectionQuery = JsonUtils.objectToPojo(req.getData(),PjCollectionQuery.class);
            // 2. 查询数据
            PjCollection pjCollection = pjCollectionMapper.getSingle(pjCollectionQuery);
            //  获取缴费方式数据字典
            Map<String, String> paymentMethodMap = Tools.mapDicByCode(factory, PAYMENT_METHOD);
            if (pjCollection != null && paymentMethodMap != null){
                if (pjCollection.getPaymentMethod() != null && paymentMethodMap.containsKey(pjCollection.getPaymentMethod().toString())){
                    pjCollection.setPaymentMethodName(paymentMethodMap.get(pjCollection.getPaymentMethod().toString()));
                }
            }
            String statusName = PjCollectionPaymentStatus.getNameByStatus(pjCollection.getStatus());
            pjCollection.setStatusName(statusName);
            MessageBean<PjCollection> message = MessageBean.create(Constant.MESSAGE_INT_SUCCESS,"工程款明细详情查询成功",PjCollection.class);
            message.setData(pjCollection);

            return message;
        } catch (Exception e) {
            logger.error("工程款明细详情查询失败: ",e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL,"工程款明细详情查询失败",null);
        }
    }
}
